﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
namespace WPFExcelReport
{
    /// <summary>
    /// 根据品种编号搜索所有需求，并自动进行累计
    /// 选择进入需要创建采购单或生产单队列，
    /// 创建生产单
    /// 创建留位关系
    /// </summary>
    public partial class TZPRWD02
    {  
        public TZPRWD02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWDECK();
            DataContext = MV;
            InitializeComponent(); 
         }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                ABAUF = "";
                return;
            } 
            ABAUF = dwMaster["WDAUFKRS"].ToString() + dwMaster["WDAUFLFD"].ToString() + dwMaster["WDAUFPOS"].ToString() + dwMaster["WDUPOS"].ToString() + "PR ";

        }
        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            dwData = TBMain.NewRow();
            dwData["WDMANDANT"] = app.Mandant;
            dwData["WDSA"] = WDSA;
            dwData["WDTYP"] = WZTYP;
            dwData["WDWAKZ"] = ARTST; 
            dwData["WDART"] = ART.Trim();
            dwData["WDVAR"] = VAR.Trim();
            dwData["WDFARBE"] = FARBE.Trim(); 
            dwData["WDBESCHICH"] = FINISH.Trim();
            dwData["WDDESS"] = DESS.Trim();
            dwData["WDCOLORIT"] = COLORIT.Trim();
            if (AUFART == "")
            {
                dwData["WDBEDST"] = "";
            }
            else
            {
                dwData["WDBEDST"] = " AND ABPAUFART='" + AUFART + "'";
            }
            SResult = TMV.QWD27(dwData);
            MergeData(SResult, false);
            base.QueryCommand(sender, e);
        }
        public override void OnEXAUFChg(string vlaue)
        {
            IsReset = false;
            IsReset = true;
            if (EXAUF.Length < 62)
                return;
            dwData = TBMain.NewRow();
            dwData["WDMANDANT"] = app.Mandant;
            dwData["WDSA"] = WDSA;
            dwData["WDTYP"] = WZTYP;
            dwData["WDWAKZ"] = EXAUF.Substring(0, 1);
            ART = EXAUF.Substring(1, 20);
            VAR = EXAUF.Substring(21, 2);
            FARBE = EXAUF.Substring(23, 10);
            FINISH = EXAUF.Substring(33, 10);
            dwData["WDART"] =EXAUF.Substring(1,20);
            dwData["WDVAR"] = EXAUF.Substring(21, 2);
            dwData["WDFARBE"] = EXAUF.Substring(23, 10);

            dwData["WDBESCHICH"] = EXAUF.Substring(33, 10);
            dwData["WDDESS"] = EXAUF.Substring(43, 10);
            dwData["WDCOLORIT"] = EXAUF.Substring(53, 10);
            if (WZTYP == "N")
            {
                dwData["WDKUNDNR"] = " AND WDZUGET + WDRESERV < WDBEDARF";
            }
            else
            {
                dwData["WDKUNDNR"] = "";
            }
            if(AUFART == "")
            {
                dwData["WDBEDST"] = "";
            }
            else
            {
                dwData["WDBEDST"] = " AND ABPAUFART='" + AUFART + "'";
            }
            
            SResult = TMV.QWD28(dwData);
            MergeData(SResult, false);
            base.OnEXAUFChg(vlaue);
        } 
    }
}
